package com.imooc.service;


import com.imooc.doman.Girl;
import com.imooc.enums.ResultEnum;
import com.imooc.exception.GirlException;
import com.imooc.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by 廖师兄
 * 2016-11-04 00:08
 */
@Service
public class GirlService {

    @Autowired
    private GirlRepository girlRepository;

    @Transactional
    public void insertTwo() {
        Girl girlA = new Girl();
        girlA.setCupSize("A");
        girlA.setAge(18);
        girlRepository.save(girlA);


        Girl girlB = new Girl();
        girlB.setCupSize("BBBB");
        girlB.setAge(19);
        girlRepository.save(girlB);
    }

    public void getAge(Integer id)throws GirlException{
        Girl girl=girlRepository.findGirlById(id);
        Integer age=girl.getAge();
        if (age<=10){
            //返回你还在上小学吧     code 100
            System.out.println("1000000");
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
        }else if(age>10 && age<16){
            //返回你可能还在上初中    code=101
            System.out.println("1111111");
            throw new GirlException(ResultEnum.MIDDLE_SCHOOL);
        }

        //如果>16岁，加钱
        //...
    }

}
